package cc.sunni.test;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * @author jl
 * @since 2021/1/17 13:48
 */
public class StreamDemo {

    public static void main(String[] args) {
        String str = "my name is java";
        Optional<String> reduce = Stream.of(str.split(" ")).reduce((x, y) -> x + "|" + y);
        System.out.println(reduce.orElse(""));
        // 带初始值
        String s = Stream.of(str.split(" ")).reduce("", (x, y) -> x + "|" + y);
        System.out.println(s);
        Integer count = Stream.of(str.split(" ")).map(e -> e.length()).reduce(0, (x, y) -> x + y);
        System.out.println(count);
    }
}
